 <?php
  use yii\helpers\Html;
  use yii\helpers\Url;
  use yii\bootstrap\ActiveForm;
  use yii\widgets\LinkPager;
  use common\models\User;

  $this->title = 'execute';
 ?>
 <section class="content">
  <div class="row">
  	<div class="col-md-12">
      <div class="box box-danger">
        <div class="box-header with-border">
          <h3 class="box-title">执行任务</h3>
        </div>
        <div class="box-body">
            <div class="info-title">
              <h4>部门承接信息</h4>
            </div>
            <?php $form = ActiveForm::begin(['action' => ['task/execute'], 'method' => 'post']);?>
				    <div class="form-group">	
		              <div class="row">
						<div class="col-xs-3">
							<label>承接关系</label>
								<select class="form-control transfer_undertake" name="pid">
									<option value="">选择承接关系</option> 
									<?php foreach ($process as $val): ?>
										<option value="<?= $val->id?>"><?= $department[$val->tran_depart]?>-<?= $department[$val->undertake_depart]?></option>
									<?php endforeach;?>
								</select>
						</div>
						<input type="hidden" name="pocde" value="<?= $pcode?>" />
						<input type="hidden" name="oid" value="<?= $order->oid?>" />
					  </div>
					</div>
					<div class="form-group">
		              <div class="row">
		                <div class="col-xs-3">
		                  <label>转接人</label>
		                  <input type="text" class="form-control" value="<?= (User::findOne(Yii::$app->user->id)->employee)?User::findOne(Yii::$app->user->id)->employee->realname:''; ?> " readonly/>
		                  <input type="hidden" name="transfer" value="<?= (User::findOne(Yii::$app->user->id)->employee)?User::findOne(Yii::$app->user->id)->employee->id:'';?>">
		                  <?=Html::error($model, 'transfer', ['style' => 'color:red'])?>
		                </div>
		                <div class="col-xs-3">
		                  <label>承接人</label>
						  <select class="form-control undertake" name="undertake">
						  	
						  </select>	
		                  <?=Html::error($model, 'undertake', ['style' => 'color:red'])?>
		                </div>
		              </div>
		            </div>
					<div class="form-group">
		              <div class="row">
  		                <div class="col-xs-3">
		                  <label>检测客户</label>
		                  <input type="text" readonly class="form-control" value="<?= $customer[$customer_order->cid]?>" />
		                </div>
		                <div class="col-xs-3">
		                  <label>检测项目</label>
		                  <input type="text" readonly class="form-control" value="<?= $product[$order->pid]?>" />
		                </div>
		                <div class="col-xs-3">
		                  <label>检测时间</label>
		                  <input type="text" class="form-control" readonly value="<?= date('Y-m-d', $order->check_time)?>" />
		                </div>
		                <div class="col-xs-3">
		                  <label>出库时间</label>
		                  	<input type="text" class="form-control out_storage_time datepicker" name="out_storage_time" readonly />
		                </div>
		              </div>
		            </div>
					<div class="form-group">
		              <div class="row">
  		                <div class="col-xs-3">
		                  <label>样本寄出单号</label>
		                  <input type="text" class="form-control send_code" name="send_code" value="" />
		                </div>
		                <div class="col-xs-3">
		                  <label>样本寄出时间</label>
		                  <input type="text" readonly class="form-control send_time datepicker" name="send_time" />
		                </div>
  		                <div class="col-xs-3">
		                  <label>快递单号</label>
		                  <input type="text" class="form-control delivery_code" name="delivery_code" value="" />
		                </div>
		                <div class="col-xs-3">
		                  <label>客户签收时间</label>
		                  <input type="text" readonly class="form-control sign_time datepicker" name="sign_time" />
		                </div>
		            </div>
	            	<div class="box-footer">
					  <button class="btn btn-primary">确定</button>
					  <button class="btn btn-warning">取消</button>
					</div>
            <?php ActiveForm::end();?>	
        </div>
       </div>
    </div>
  </div>
 </section>

<!-- 引入所需js文件 -->
<script type="text/javascript" src="js/jquery.js"></script>
<!-- datepicker时间控件 -->
<script type="text/javascript" src="plugins/date.js" ></script>
<script type="text/javascript" src="plugins/iscroll.js" ></script>
<script src="plugins/jquery.scs.min.js"></script>
<script src="plugins/CNAddrArr.min.js"></script>
<script src="plugins/datepicker/bootstrap-datepicker.js"></script> 
 <script>
   /*时间选择器*/
	$('.datepicker').datepicker({
		autoclose: true
	});

	/*获取部门员工*/
 	$(".transfer_undertake").change(function(){
 		var pid = $(this).val();
 		if (pid) {
    		var url = "<?= Url::toRoute('task/getemployee')?>";
		    var _csrf ="<?= Yii::$app->request->getCsrfToken()?>";
		    $.ajax({
		      url:url,
		      type:'GET',
		      dataType:'json',
		      data: {
		        pid:pid,
		        _csrf:_csrf
		      },
		      success: function(json){
		      	var html = "";
		      	if (json.flag) {
	                $.each(json.employee, function (n, value) {
	                  html += "<option value='"+value.id+"'>"+value.realname+"</option>";
	                });
	               	var control_arr = json.control.split(",");
	               	controlForm(control_arr);
		      	} else {
		      		html = "<option value=''>部门暂无员工</option>";
		      	}
		      	$(".undertake").html(html);
		      },
		      error:function(){
		        alert('网络忙');
		      }
		    });
 		}
 	});

 	/* 动态控制表单可选功能 */
 	function controlForm(param_arr) {
 		if(contains(param_arr, 'send_address')){
	     //     var html = "<div class='out_storage_time'>"+
	     //              	  "<input type='text' class='form-control datepicker' name='out_storage_time' readonly />"+
	     //                "</div>";
		    // $(".out_storage_time").html(html);
		            
 		} else {
 			// $(".out_storage_time").html("<?= date('Y-m-d', $order->out_storage_time) ?>");
 			$(".out_storage_time").datepicker('disable');
 		}

 		// if(contains(param_arr, 'send_code')){
 		// 	$(".send_code").attr('disabled');
 		// } else {
 		// 	$(".send_code").removeAttr('disabled');
 		// }

 	} 

 	/*判断元素是否在数组中*/
 	function contains(arr, obj) {
	  var i = arr.length;
	  while (i--) {
	    if (arr[i] === obj) {
	      return true;
	    }
	  }
	  return false;
	}

 </script>     